<template>
	<view class="content">
		<view class="home-container">
			<!--查成分-->
			<view class="home-bar">
				<view class="home-title">
					<view class="big-title">{{bigTitle}}</view>
					<view class="small-title">{{smallTitle}}</view>
				</view>
				<view class="home-logo">
					<image :src="configInfo.home_logo"></image>
				</view>
			</view>
			<!--搜索区域-->
			<view class="home-search">
				<input type="text" class="home-search-input" @confirm="searchEnter(searchValue)"
					v-model="searchValue" />
				<image class="home-search-img" src="/static/search_icon.png" @click="searchEnter(searchValue)"></image>
			</view>
			<!--大家都在搜-->
			<view class="everyone-search">
				大家都在搜：
				<template v-for="(item,index) in searchKeywords">
					<text @click="searchEnter(item)" v-if="index <=1">{{item}}</text>
					<span class="line" v-if="index  === 0">I</span>
				</template>
			</view>
		</view>
	</view>
	<FootTabs></FootTabs>

</template>

<script setup lang="ts">
	import { ref, reactive, getCurrentInstance } from 'vue'
	import { onLoad, onShow } from "@dcloudio/uni-app"
	import { initConfig, setPageTitle } from '@/utils/common';
	const searchValue = ref('')
	const searchEnter = (value : string) => {
		uni.navigateTo({
			url: '/pages/search/index?keyword=' + value
		});
	}
	const searchKeywords = ref([])
	let configInfo : any = reactive({})
	const bigTitle = ref();
	const smallTitle = ref();
	const getConfig = async () => {
		const { data } = await initConfig();
		const homeTitles = data?.home_title?.split(',');
		console.log('homeTitles', homeTitles)
		bigTitle.value = homeTitles?.[0];
		smallTitle.value = homeTitles?.[1];
		Object.assign(configInfo, data)

		searchKeywords.value = data?.search_keyword || []
		setPageTitle(data?.name)
	}

	onLoad(() => {
		getConfig()
	})

	onShow(() => {
		const { proxy } : any = getCurrentInstance()
		const newMethod = proxy.$wxShare;
		var url = window.location.protocol + "//" + window.location.host;
		const pages = getCurrentPages();
		const link = url + "/#/" + pages[pages.length - 1].route
		newMethod("", "", link)
	})
</script>

<style lang="scss" scoped>
	.home-container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: calc(100vh - 3.125rem);

		.home-bar {
			align-items: center;
			display: flex;
			justify-content: center;
			width: 100vw;

			.home-title {
				margin-right: 20rpx;
				color: #3e3a39;
				font-family: PingFangSC-Regular, PingFang SC;
				display: flex;
				flex-direction: column;

				.big-title {
					font-size: 36rpx;
					font-weight: 400;
					margin-bottom: 10rpx;
				}

				.small-title {
					color: #999;
					font-size: 36rpx;
				}

			}

			.home-logo {
				display: flex;
				align-items: center;

				image {
					height: 96rpx;
					width: 96rpx;
				}

			}
		}

		.home-search {
			align-items: center;
			background: #ededed;
			border-radius: 50rpx;
			display: flex;
			flex-wrap: wrap;
			height: 72rpx;
			justify-content: center;
			margin: 44rpx auto 0;
			width: 522rpx;

			.home-search-input {
				font-weight: 400;
				height: 40rpx;
				margin-left: 8rpx;
				width: 400rpx;
			}

			.home-search-img {
				height: 40rpx;
				margin-left: 28rpx;
				width: 40rpx;
			}
		}

		.everyone-search {
			color: #999;
			font-family: PingFangSC-Regular, PingFang SC;
			font-size: 28rpx;
			margin-top: 42rpx;
			text-align: center;

			.line {
				font-size: 14px;
				font-weight: bold;
				margin: 0 13px;
			}
		}
	}


	.text-area {
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>